package com.nexus.core.properties;

import com.nexus.core.utils.PropertiesUtils;
import org.springframework.core.env.PropertiesPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PropertySourceFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * 解析外部yaml/properties处理器,用于加载指定的配置文件
 *
 * @Date 2025/9/17 02:35
 * @Author luzhengning
 **/
public class ExternalPropertySourceFactory implements PropertySourceFactory {

    @Override
    public PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
        //读取配置文件环境
        Properties properties = PropertiesUtils.convertReourceOnEnv(name);
        if(properties == null){
            throw new IllegalArgumentException("找不到对应的配置文件："+name);
        }
        return new PropertiesPropertySource(name, properties);
    }


}

